<template>
  <div class="login-wrapper">
    <div class="login-header">
      <div class="logo-img-box">
        <img
          class="img"
          src="https://p1.meituan.net/travelcube/86c5b686264c3cda292c30f623970f955983.png"
        />
      </div>
    </div>
    <div class="login-form">
      <van-form @submit="onSubmit">
        <van-cell-group inset>
          <router-link to="/phoneNumberPlace"> 中国+86> </router-link>

          <van-field
            v-model="phoneNumber"
            center
            clearable
            placeholder="请输入手机号"
            :rules="[{ pattern, message: '请输入正确的手机号' }]"
          >
            <template #button>
              <van-button size="small" type="primary">获取验证码</van-button>
            </template>
          </van-field>
          <van-field
            v-model="code"
            placeholder="请输入验证码"
            :rules="[{ required: true, message: '请填写验证码' }]"
          />
        </van-cell-group>
        <div style="margin: 16px">
          <van-button round block type="primary" native-type="submit">
            登录
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useUserStore } from "@/store";
import { useRouter } from "vue-router";

const userStore = useUserStore();
const router = useRouter();
const phoneNumber = ref("");
const code = ref("");
const pattern = /1\d{10}/;
// // 校验函数返回 true 表示校验通过，false 表示不通过
// const validator = (val) => /1\d{10}/.test(val);

// // 校验函数可以直接返回一段错误提示
// const validatorMessage = (val) => {
//   console.log(val,/1\d{10}/.test(val))
//   return `${val} 不合法，请重新输入`;
// }
const onSubmit = (values) => {
  console.log("submit", values);
  userStore.setUserId("admin");
  localStorage.setItem("userId", "admin");
  router.go(-1);
};
</script >

<style lang='less' scoped>
.login-wrapper {
  .login-header {
    height: 2.7rem;
    box-sizing: border-box;
    padding-top: 0.5rem;
    text-align: center;
    display: flex;
    justify-content: center;
    .logo-img-box {
      width: 21.3vw;
      height: 21.3vw;
      .img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .login-form {
    padding: 0.3rem 0.65rem 0 0.65rem;
  }
}
</style>